<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文件上传和下载测试</title>
</head>
<body>
<h1>文件上传</h1>
<form id="uploadForm" enctype="multipart/form-data">
    <input type="file" name="file" id="fileInput" required>
    <button type="submit">上传文件</button>
</form>

<h1>文件下载</h1>
<ul id="fileList">
    <!-- 下载链接将在此动态生成 -->
</ul>

<script>
    document.getElementById('uploadForm').addEventListener('submit', function(event) {
        event.preventDefault(); // 阻止默认提交行为

        var formData = new FormData();
        formData.append('file', document.getElementById('fileInput').files[0]);

        fetch('http://localhost:9494/chgy/system/file/upload', {
            method: 'POST',
            body: formData
        })
            .then(response => response.text())
            .then(fileAccessUrl => {
                var downloadLink = document.createElement('a');
                downloadLink.href = fileAccessUrl;
                downloadLink.textContent = '下载文件';
                var listItem = document.createElement('li');
                listItem.appendChild(downloadLink);
                document.getElementById('fileList').appendChild(listItem);
            })
            .catch(error => console.error('文件上传失败:', error));
    });
</script>
</body>
</html>
